package top.wu2020.lazy.ws.chat.controller;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
 
@Controller
public class WebSocketController {
 
    // 处理前缀为"/chat"的消息
    @MessageMapping("/sendMsg")
    @SendTo("/topic/publicChat")
    public String chatMessage(String message) {
        // 对接收到的消息进行处理，并返回响应
        return "Public message: " + message;
    }
 
    // 处理前缀为"/privatechat"的消息
    @MessageMapping("/privatechat.message")
    @SendTo("/topic/privateChat")
    public String privateChatMessage(String message) {
        // 对接收到的消息进行处理，并返回响应
        return "Private message: " + message;
    }


    @MessageMapping("/connect")
    public void connect() {
        System.out.println("connect");
    }


}